import cn.hutool.core.date.StopWatch;
import cn.hutool.crypto.digest.DigestUtil;

/**
 * @Author: yudaxian
 * @Description: TODO
 * @DateTime: 2024/10/8 10:42
 **/
public class MD5Digest {
    public static void main(String[] args) {
        String solt = "yudaxian";
        // ----------------------- MD5 加密 ----------
        StopWatch stopWatch = new StopWatch();
        stopWatch.start("md5");
        System.out.println("---------- MD5 加密 ----------");
        System.out.println(DigestUtil.md5Hex("123456"));
        System.out.println(DigestUtil.md5Hex("123456"));
        System.out.println(DigestUtil.md5Hex("123456" + solt));
        stopWatch.stop();
        System.out.println(stopWatch.getLastTaskName() +  "--" + stopWatch.getLastTaskTimeMillis() + "ms");
        // md5 登录判断
        if (DigestUtil.md5Hex("12456" + solt).equals("019ecb556930f0207ed93fe7b43d0873")) {
            System.out.println("登录成功");
        } else {
            System.out.println("登录失败");
        }

        stopWatch.start("bcrypt");
        // ------------- Bcrypt 加密 ----------
         System.out.println("---------- Bcrypt 加密 ----------");
         System.out.println(DigestUtil.bcrypt("123456"));
         System.out.println(DigestUtil.bcrypt("123456"));
         System.out.println(DigestUtil.bcrypt("123456"));
         stopWatch.stop();
        System.out.println(stopWatch.getLastTaskName() +  "--" + stopWatch.getLastTaskTimeMillis() + "ms");

    }
}
